package com.zhike.b2b.user.impl;

import com.saas.biz.commen.MD5;
import com.saas.biz.commen.CommMethodMgr;
import com.saas.biz.dao.userDAO.MyConstant;
import com.saas.biz.dao.userDAO.RegUserDAO;
import com.saas.biz.dao.userDAO.RegUserExt;
import com.saas.biz.paramMgr.ParamInfo;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.exp.SaasApplicationException;
import com.saas.sys.log.Logger;
import com.zhike.b2b.dao.Dbtable;

import java.io.PrintStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

public class UserInforProc
{
  Logger log = new Logger(this);
  Buffers inBuffer;
  Buffers outBuffer;
  Dbtable tradeQuery = new Dbtable();
  CommMethodMgr commen = new CommMethodMgr();
  private String regemail;
  ArrayList queryResult = new ArrayList();

  public CommMethodMgr getCommen()
  {
    return this.commen;
  }

  public void setCommen(CommMethodMgr paramcommMethodMgr)
  {
    this.commen = paramcommMethodMgr;
  }

  public Buffers getInBuffer()
  {
    return this.inBuffer;
  }

  public void setInBuffer(Buffers paramBuffers)
  {
    this.inBuffer = paramBuffers;
  }

  public Logger getLog()
  {
    return this.log;
  }

  public void setLog(Logger paramLogger)
  {
    this.log = paramLogger;
  }

  public Buffers getOutBuffer()
  {
    return this.outBuffer;
  }

  public void setOutBuffer(Buffers paramBuffers)
  {
    this.outBuffer = paramBuffers;
  }

  public ArrayList getQueryResult()
  {
    return this.queryResult;
  }

  public void setQueryResult(ArrayList paramArrayList)
  {
    this.queryResult = paramArrayList;
  }

  public String getRegemail()
  {
    return this.regemail;
  }

  public void setRegemail(String paramString)
  {
    this.regemail = paramString;
  }

  public Dbtable getTradeQuery()
  {
    return this.tradeQuery;
  }

  public void setTradeQuery(Dbtable paramDbtable)
  {
    this.tradeQuery = paramDbtable;
  }

  public RegUserExt UserExtGet(Buffers paramBuffers, Class paramClass)
  {
    MyConstant localMyConstant = new MyConstant(paramClass);
    ArrayList localArrayList = localMyConstant.ListGetAllConstant();
    RegUserExt localRegUserExt = new RegUserExt();
    for (int i = 0; i < localArrayList.size(); i++)
    {
      String str = ":V" + (String)localArrayList.get(i);
      localRegUserExt.setParam(str, htmEncode(paramBuffers.getString((String)localArrayList.get(i))));
    }
    return localRegUserExt;
  }

  public ArrayList ListAllUser(String paramString, int paramInt1, int paramInt2)
  {
    if (paramInt1 > 0)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    RegUserExt localRegUserExt = new RegUserExt();
    try
    {
      localRegUserExt.setParam(":VCUST_TYPE", paramString);
      return localRegUserExt.selByList("SEL_USER_BY_USER_TYPE", paramInt1, paramInt2);
    }
    catch (Exception ex)
    {
      log.LOG_ERROR(ex.getMessage());
    }
    return null;
  }

  public int ListAllUser(String paramString)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VCUST_TYPE", paramString);
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_USER_TYPE");
    if (localArrayList != null)
      return localArrayList.size();
    return 0;
  }

  public ArrayList getAllUser(int paramInt1, int paramInt2, String paramString1, String paramString2, String paramString3)
  {
    if (paramInt1 > 0)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VCUST_TYPE", paramString1);
    if (!paramString2.equals(""))
      localRegUserExt.setParam(":VKEY_WORD", "%" + paramString2 + "%");
    else
      localRegUserExt.setParam(":VKEY_WORD", paramString2 + "%");
    if (!paramString3.equals(""))
      localRegUserExt.setParam(":VCUST_NAME", "%" + paramString3 + "%");
    else
      localRegUserExt.setParam(":VCUST_NAME", paramString3 + "%");
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_USERANDCUST", paramInt1, paramInt2);
    if ((localArrayList != null) && (localArrayList.size() > 0))
      return localArrayList;
    return null;
  }

  public int getAllUser(String paramString1, String paramString2, String paramString3)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VCUST_TYPE", paramString1);
    if (!paramString2.equals(""))
      localRegUserExt.setParam(":VKEY_WORD", "%" + paramString2 + "%");
    else
      localRegUserExt.setParam(":VKEY_WORD", paramString2 + "%");
    if (!paramString3.equals(""))
      localRegUserExt.setParam(":VCUST_NAME", "%" + paramString3 + "%");
    else
      localRegUserExt.setParam(":VCUST_NAME", paramString3 + "%");
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_USERANDCUST");
    if (localArrayList != null)
      return localArrayList.size();
    return 0;
  }

  public ArrayList ListUserByUserId(String paramString)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_ID", paramString);
    return localRegUserExt.selByList("SEL_USER_BY_USER_ID");
  }

  public ArrayList ListUserByUserId_More(String paramString)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_ID", paramString);
    return localRegUserExt.selByList("SEL_USER_UPDATE_ONE");
  }

  public ArrayList ListAllUserState(String paramString1, String paramString2, int paramInt1, int paramInt2)
  {
    if (paramInt1 > 0)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    RegUserExt localRegUserExt = new RegUserExt();
    try
    {
      localRegUserExt.setParam(":VCUST_TYPE", paramString1);
      localRegUserExt.setParam(":VUSER_STATE", paramString2);
      return localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT", paramInt1, paramInt2);
    }
    catch (Exception ex)
    {
        log.LOG_ERROR(ex.getMessage());
    }
    return null;
  }

  public int ListAllUserState(String paramString1, String paramString2)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VCUST_TYPE", paramString1);
    localRegUserExt.setParam(":VUSER_STATE", paramString2);
    if (localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT") != null)
      return localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT").size();
    return 0;
  }

  public ArrayList ListAllUserState(String paramString1, String paramString2, int paramInt1, int paramInt2, String paramString3)
  {
    if (paramInt1 > 0)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VCUST_TYPE", paramString1);
    localRegUserExt.setParam(":VUSER_STATE", paramString2);
    localRegUserExt.setParam(":VKEY_WORD", '%' + paramString3 + '%');
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT_KEYWORD", paramInt1, paramInt2);
    return localArrayList;
  }

  public int ListAllUserState(String paramString1, String paramString2, String paramString3)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VCUST_TYPE", paramString1);
    localRegUserExt.setParam(":VUSER_STATE", paramString2);
    localRegUserExt.setParam(":VKEY_WORD", '%' + paramString3 + '%');
    log.LOG_ERROR(paramString3);
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT_KEYWORD");
    if (localArrayList == null)
      return 0;
    return localArrayList.size();
  }

  public ArrayList ListAllUser(String paramString1, int paramInt1, int paramInt2, String paramString2)
  {
    if (paramInt1 > 0)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VCUST_TYPE", paramString1);
    localRegUserExt.setParam(":VKEY_WORD", '%' + paramString2 + '%');
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_TITLE", paramInt1, paramInt2);
    return localArrayList;
  }

  public int ListAllUser(String paramString1, String paramString2)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VCUST_TYPE", paramString1);
    localRegUserExt.setParam(":VKEY_WORD", '%' + paramString2 + '%');
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_TITLE");
    if (localArrayList == null)
      return 0;
    return localArrayList.size();
  }

  public void voidUpdatePassword(Buffers paramBuffers)
  {
    this.inBuffer = paramBuffers;
    this.outBuffer = paramBuffers;
    RegUserExt localRegUserExt = new RegUserExt();
    String str = "";
    MD5 localMD5 = new MD5();
    str = localMD5.getMD5(paramBuffers.getString("PASSWD").getBytes());
    localRegUserExt.setParam(":VPASSWD", str);
    localRegUserExt.setParam(":VUSER_ID", paramBuffers.getString("USER_ID"));
    this.tradeQuery.executeBy(localRegUserExt.insBy("CHANGE_USER_PASSWORD"));
  }

  public void voidUpdateUserState(Buffers paramBuffers)
    throws SaasApplicationException
  {
    ParamInfo localParamInfo = new ParamInfo();
    String str = "";
    if ("1".equals(this.inBuffer.getString("USER_STATE")))
      try
      {
        str = localParamInfo.getParameter("default_role");
      }
      catch (SaasApplicationException localSaasApplicationException)
      {
        localSaasApplicationException.printStackTrace();
      }
    this.inBuffer = paramBuffers;
    this.outBuffer = paramBuffers;
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date localDate = new Date();
    this.log.LOG_INFO("����voidUpdateUserState+++++++++++++++++++++");
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_ID", paramBuffers.getString("USER_ID"));
    localRegUserExt.setParam(":VUSER_STATE", paramBuffers.getString("USER_STATE"));
    localRegUserExt.setParam(":VUSER_STATE_DATE", localSimpleDateFormat.format(localDate));
    localRegUserExt.setParam(":VROLE_AUTH_ID", str);
    this.tradeQuery.executeBy(localRegUserExt.insBy("UPDATE_USER_STATE"));
    this.log.LOG_INFO("�˳�voidUpdateUserState+++++++++++++++++++++");
  }

  public void voidApplyLogout(Buffers paramBuffers)
    throws SaasApplicationException
  {
    this.inBuffer = paramBuffers;
    this.outBuffer = paramBuffers;
    this.log.LOG_INFO("����voidApplyLogout+++++++++++++++++++++");
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_ID", paramBuffers.getString("USER_ID"));
    localRegUserExt.setParam(":VUSER_STATE", paramBuffers.getString("USER_STATE"));
    localRegUserExt.setParam(":VREMARK", htmEncode(paramBuffers.getString("REMARK")));
    this.tradeQuery.executeBy(localRegUserExt.insBy("APPLY_USER_LOGOUT"));
    this.log.LOG_INFO("�˳�voidApplyLogout+++++++++++++++++++++");
  }

  public ArrayList ListGetUserState(String paramString)
    throws SaasApplicationException
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_ID", paramString);
    return localRegUserExt.selByList("GET_USER_STATE_FROM_USER");
  }

  public void voidCheckUserState(Buffers paramBuffers)
    throws SaasApplicationException
  {
    ParamInfo localParamInfo = new ParamInfo();
    String str = "";
    if ("1".equals(paramBuffers.getString("USER_STATE")))
      str = localParamInfo.getParameter("default_role");
    this.inBuffer = paramBuffers;
    this.outBuffer = paramBuffers;
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date localDate = new Date();
    this.log.LOG_INFO("����voidCheckUserState+++++++++++++++++++++");
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_ID", paramBuffers.getString("USER_ID"));
    localRegUserExt.setParam(":VUSER_STATE", paramBuffers.getString("USER_STATE"));
    localRegUserExt.setParam(":VCHECK_USER", paramBuffers.getString("CHECK_USER"));
    localRegUserExt.setParam(":VBACK_REASON", htmEncode(paramBuffers.getString("BACK_REASON")));
    localRegUserExt.setParam(":VCHECK_TIME", localSimpleDateFormat.format(localDate));
    localRegUserExt.setParam(":VROLE_AUTH_ID", str);
    this.tradeQuery.executeBy(localRegUserExt.insBy("CHECK_USER_STATE"));
    this.log.LOG_INFO("�˳�voidCheckUserState+++++++++++++++++++++");
  }

  public void voidUpdateUser(Buffers paramBuffers)
  {
    this.log.LOG_INFO("����voidUpdateUser����.........................");
    this.inBuffer = paramBuffers;
    this.outBuffer = paramBuffers;
    int i = 0;
    RegUserExt localRegUserExt = UserExtGet(paramBuffers, RegUserDAO.class);
    try
    {
      this.tradeQuery.executeBy(localRegUserExt.insBy("UPDATE_USER_UPDATE_ONE"));
    }
    catch (Exception localException)
    {
      this.log.LOG_INFO(localException.getMessage());
      i = -1;
    }
    finally
    {
      if (i != 0)
      {
        this.outBuffer.setInt("RESULT_CODE", -1);
        this.outBuffer.setString("RESULT_INFO", "ҵ����ʧ�ܣ�");
      }
      else
      {
        this.outBuffer.setInt("RESULT_CODE", 0);
        this.outBuffer.setString("RESULT_INFO", "ҵ����ɹ���");
      }
      this.log.LOG_INFO("�뿪voidUpdateUser����.........................");
    }
  }

  public ArrayList ListAllUserStates(String paramString, int paramInt1, int paramInt2)
  {
    if (paramInt1 > 0)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    RegUserExt localRegUserExt = new RegUserExt();
    try
    {
      localRegUserExt.setParam(":VUSER_TYPE", paramString);
      return localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT_ALL", paramInt1, paramInt2);
    }
    catch (Exception ex)
    {
        log.LOG_ERROR(ex.getMessage());
    }
    return null;
  }

  public int ListAllUserStates(String paramString)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_TYPE", paramString);
    if (localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT_ALL") != null)
      return localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT_ALL").size();
    return 0;
  }

  public ArrayList ListAllUserStates(String paramString1, int paramInt1, int paramInt2, String paramString2)
  {
    if (paramInt1 > 0)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_TYPE", paramString1);
    localRegUserExt.setParam(":VKEY_WORD", '%' + paramString2 + '%');
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT_KEYWORD_ALL", paramInt1, paramInt2);
    return localArrayList;
  }

  public int ListAllUserStates(String paramString1, String paramString2)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_TYPE", paramString1);
    localRegUserExt.setParam(":VKEY_WORD", '%' + paramString2 + '%');
    log.LOG_ERROR(paramString2);
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT_KEYWORD_ALL");
    if (localArrayList == null)
      return 0;
    return localArrayList.size();
  }

  public ArrayList ListGetAdminPassword(String paramString)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_ID", paramString);
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_ADMIN");
    return localArrayList;
  }

  public void piliangUser_State(Buffers paramBuffers)
  {
    this.inBuffer = paramBuffers;
    this.outBuffer = paramBuffers;
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date localDate = new Date();
    String str1 = paramBuffers.getString("USER_ID");
    String[] arrayOfString = str1.split(",");
    ParamInfo localParamInfo = new ParamInfo();
    String str2 = "";
    if ("1".equals(paramBuffers.getString("USER_STATE")))
      try
      {
        str2 = localParamInfo.getParameter("default_role");
      }
      catch (SaasApplicationException localSaasApplicationException)
      {
        localSaasApplicationException.printStackTrace();
      }
    for (int i = 0; i < arrayOfString.length; i++)
    {
      log.LOG_ERROR("�����û�״̬��ʼ");
      log.LOG_ERROR("USER_ID:" + arrayOfString[i]);
      log.LOG_ERROR("USER_STATE:" + paramBuffers.getString("USER_STATE"));
      RegUserExt localRegUserExt = new RegUserExt();
      localRegUserExt.setParam(":VUSER_ID", arrayOfString[i]);
      localRegUserExt.setParam(":VUSER_STATE", paramBuffers.getString("USER_STATE"));
      localRegUserExt.setParam(":VUSER_STATE_DATE", localSimpleDateFormat.format(localDate));
      localRegUserExt.setParam(":VROLE_AUTH_ID", str2);
      this.tradeQuery.executeBy(localRegUserExt.insBy("UPDATE_USER_STATE"));
    }
  }

  public void addAdminUser(Buffers paramBuffers)
  {
    this.inBuffer = paramBuffers;
    this.outBuffer = paramBuffers;
    RegUserExt localRegUserExt = UserExtGet(paramBuffers, RegUserDAO.class);
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date localDate = new Date();
    localRegUserExt.setParam(":VUSER_ID", getMaxUser_Id());
    localRegUserExt.setParam(":VADD_DATE", localSimpleDateFormat.format(localDate));
    localRegUserExt.setParam(":VOPER_TIME", localSimpleDateFormat.format(localDate));
    int i = 0;
    try
    {
      this.tradeQuery.executeBy(localRegUserExt.insBy("ADD_USER_ADMIN"));
    }
    catch (Exception localException)
    {
      this.log.LOG_INFO(localException.getMessage());
      i = -1;
    }
    finally
    {
      if (i != 0)
      {
        this.outBuffer.setInt("RESULT_CODE", -1);
        this.outBuffer.setString("RESULT_INFO", "ҵ����ʧ�ܣ�");
      }
      else
      {
        this.outBuffer.setInt("RESULT_CODE", 0);
        this.outBuffer.setString("RESULT_INFO", "ҵ����ɹ���");
      }
      this.log.LOG_INFO("�뿪addAdminUser����.........................");
    }
  }

  public String getMaxUser_Id()
  {
    RegUserExt localRegUserExt = new RegUserExt();
    ArrayList localArrayList = localRegUserExt.selByList("SEL_MAX_USER_ID");
    String str = "000000000000000";
    if ((localArrayList != null) && (localArrayList.size() > 0))
    {
      Object localObject = localArrayList.get(0);
      HashMap localHashMap = (HashMap)localObject;
      if (localHashMap.get("maxid") != null)
      {
        str = localHashMap.get("maxid").toString();
        try
        {
          return String.valueOf(Integer.parseInt("maxid") + 1);
        }
        catch (Exception ex)
        {
          log.LOG_ERROR("getMaxUser_Id执行出错："+ex.getMessage());
          return str;
        }
      }
    }
    return str;
  }

  public int getUserNameExist(String paramString)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    localRegUserExt.setParam(":VUSER_NAME", paramString);
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_NAME_EXIST");
    if ((localArrayList != null) && (localArrayList.size() > 0))
      return 1;
    return -1;
  }

  public ArrayList getCompany(String paramString)
  {
    RegUserExt localRegUserExt = new RegUserExt();
    ArrayList localArrayList = localRegUserExt.selByList("SEL_USER_BY_USER_TYPE_UT_KEYWORD_ALL");
    return localArrayList;
  }

  public static String htmEncode(String paramString)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    int i = paramString.length();
    for (int j = 0; j < i; j++)
    {
      char c = paramString.charAt(j);
      switch (c)
      {
      case '<':
        localStringBuffer.append("&lt;");
        break;
      case '>':
        localStringBuffer.append("&gt;");
        break;
      case '&':
        localStringBuffer.append("&amp;");
        break;
      case '"':
        localStringBuffer.append("&quot;");
        break;
      case '©':
        localStringBuffer.append("&copy;");
        break;
      case '®':
        localStringBuffer.append("&reg;");
        break;
      case '¥':
        localStringBuffer.append("&yen;");
        break;
      case '€':
        localStringBuffer.append("&euro;");
        break;
      case '™':
        localStringBuffer.append("&#153;");
        break;
      case '\r':
        if ((j >= i - 1) || (paramString.charAt(j + 1) != '\n'))
          continue;
        localStringBuffer.append("<br>");
        j++;
        break;
      case ' ':
        if ((j >= i - 1) || (paramString.charAt(j + 1) != ' '))
          break;
        localStringBuffer.append(" &nbsp;");
        j++;
        break;
      }
      localStringBuffer.append(c);
    }
    return new String(localStringBuffer.toString());
  }
}

